use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        // Replace the sample below with your own migration scripts
        // todo!();

        manager
            .create_table(
                Table::create()
                    .table("post")
                    .if_not_exists()
                    .col(pk_auto("id"))
                    .col(string("title"))
                    .col(string("text"))
                    .to_owned(),
            )
            .await?;

        // 插入两条示例数据
        manager
            .exec_stmt(
                Query::insert()
                    .into_table("post")
                    .columns(["title", "text"])
                    .values_panic([Expr::val("Hello Conferris"), Expr::val("Sample text for Conferris post")])
                    .values_panic([Expr::val("Migration Guide"), Expr::val("How to write migrations in SeaORM")])
                    .to_owned(),
            )
            .await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        // Replace the sample below with your own migration scripts
        // todo!();

        manager
            .drop_table(Table::drop().table("post").to_owned())
            .await
    }
}
